const {getAuthor} = require('../../dao/get-author')
const getImage = require('../../dao/get-image')

function initShareMsg(shareMsg) {
    shareMsg.statusCode = false
    shareMsg.shareList = []
}

function setStatus(shareMsg, bool) {
    shareMsg.statusCode = bool
    return shareMsg
}

function setShareList(oneShare) {
    return new Promise()
}

async function getImages(imageIds) {
    let imageArr = []
    for (let i of imageIds) {
        imageArr.push(await getImage(i))
    }
    return imageArr
}

async function setOneShare(shareNode) {
    let imageIds = (shareNode.images).split(','),
        // 获取多张图片
        imageArr = await getImages(imageIds),
        //获取作者信息
        authorId = shareNode.user_id,
        author = await getAuthor(authorId),
        authorImageId = author.portrait_id

    author.userLogo = await getImage(authorImageId)
    //  定义oneShare
    let oneS = {}
    oneS.images = imageArr
    oneS.author = author
    oneS.shareId = shareNode.id
    oneS.totalPraise = shareNode.total_praise
    oneS.totalComment = shareNode.total_comment
    oneS.createTime = shareNode.create_time
    oneS.content = shareNode.description
    return oneS
}

module.exports = {
    initShareMsg,
    setStatus,
    setShareList,
    setOneShare
}